import { BasicColumn } from '@/components/Table';
import { h } from 'vue';
import { CaretDownFilled } from '@ant-design/icons-vue';
// 自定义过滤图标的方法
// 定义 filterIcon 方法
const filterIcon = (filtered, onFilter, column) => {
  // console.log(filtered, onFilter, column)
  return h(CaretDownFilled, {
    style: {
      color: filtered ? '#ABBACD' : undefined,
      fontSize: '15px'
    },
    // onClick: () => onFilter(null, column),
  });
};
let tabType = ''
export const setTabType = (type: any) => {
  tabType = type
  console.log('tabType------------', tabType)
}

function getName(type: string) {
  const map = {
    peiXunGuan: "培训官",
    kaoHeGuan: "考核官",
    quDao: "渠道HR",
    mianShiGuan: "面试官",
    weiHu: "维护HR"
  }
  return map[type] || ""
}

const commonColumns: any = {
  name: {
    title: '姓名',
    dataIndex: 'name',
    key: 'name',
    fixed: 'left',
    formType: 'select',
    otherFormType: 'search',
    customFilterDropdown: true,
    filterIcon,
    width: 120
  },
  preserveUserId: {
    title: '姓名',
    dataIndex: 'name',
    key: 'preserveUserId',
    fixed: 'left',
    formType: 'select',
    otherFormType: 'search',
    customFilterDropdown: true,
    filterIcon,
    width: 120
  },
  channel: {
    title: '姓名',
    dataIndex: 'name',
    key: 'channel',
    fixed: 'left',
    formType: 'select',
    otherFormType: 'search',
    customFilterDropdown: true,
    filterIcon,
    width: 120
  },
  interviewOfficer: {
    title: '姓名',
    dataIndex: 'name',
    key: 'interviewOfficer',
    fixed: 'left',
    formType: 'select',
    otherFormType: 'search',
    customFilterDropdown: true,
    filterIcon,
    width: 120
  },
  examers: {
    title: '姓名',
    dataIndex: 'name',
    key: 'examers',
    fixed: 'left',
    formType: 'select',
    otherFormType: 'search',
    customFilterDropdown: true,
    filterIcon,
    width: 120
  },
  trainers: {
    title: '姓名',
    dataIndex: 'name',
    key: 'trainers',
    fixed: 'left',
    formType: 'select',
    otherFormType: 'search',
    customFilterDropdown: true,
    filterIcon,
    width: 120
  },
  phone: {
    title: '手机号',
    dataIndex: 'phone',
    key: 'phone',
    fixed: 'left',
    formType: 'input',
    customFilterDropdown: true,
    filterIcon
  },
  kaoHeShu: {
    title: '考核数',
    dataIndex: 'examineCount',
    key: 'examineCount',
    sorter: (a, b) => a.examineCount - b.examineCount,
    tooltip: () =>   tabType === 'peiXunGuan' ? '此培训官参与的所有期培训中包含的【培训-培训中-中途劝退】状态的数量之和' : `经历过【考核】状态归属此${getName(tabType)}的数量`
  },
  tongGuoLv: {
    title: '通过率',
    dataIndex: 'examinePassRate',
    key: 'examinePassRate',
    sorter: (a, b) => percentageToDecimal(a.examinePassRate) - percentageToDecimal(b.examinePassRate),
    tooltip: () => '考核通过数÷考核数'
  },
  ruZhiShu: {
    title: '入职数',
    dataIndex: 'alreadyEntryCount',
    key: 'alreadyEntryCount',
    sorter: (a, b) => a.alreadyEntryCount - b.alreadyEntryCount,
    tooltip: () => `所有入职归属此${tabType === 'weiHu' ? '维护HR' : tabType === 'peiXunGuan' ? '培训官' : tabType === 'kaoHeGuan' ? '考核官' : '面试官'}的数量`
  },
  ruZhiLv: {
    title: '入职率',
    dataIndex: 'entryRate',
    key: 'entryRate',
    sorter: (a, b) => percentageToDecimal(a.entryRate) - percentageToDecimal(b.entryRate),
    tooltip: () => tabType === 'quDao' ? '入职人数÷简历量' : '入职÷录取'
  },
  liZhiShu: {
    title: '离职数',
    dataIndex: 'departCount',
    key: 'departCount',
    sorter: (a, b) => a.departCount - b.departCount,
    tooltip: () => `【离职】状态归属此${tabType === 'weiHu' ? '维护HR' : tabType === 'peiXunGuan' ? '培训官' : tabType === 'kaoHeGuan' ? '考核官' : '面试官'}的数量`
  },
  liZhiLv: {
    title: '离职率',
    dataIndex: 'departRate',
    key: 'departRate',
    sorter: (a, b) => percentageToDecimal(a.departRate) - percentageToDecimal(b.departRate),
    tooltip: () => '离职÷入职'
  },
  quanTuiShu: {
    title: '劝退数',
    dataIndex: 'puaCount',
    key: 'puaCount',
    sorter: (a, b) => a.puaCount - b.puaCount,
    tooltip: () => `【实习中-劝退】【试用期-劝退】状态归属此${tabType === 'weiHu' ? '维护HR' : tabType === 'peiXunGuan' ? '培训官' : tabType === 'kaoHeGuan' ? '考核官' : '面试官'}的数量`
  },
  quanTuiLv: {
    title: '劝退率',
    dataIndex: 'puaRate',
    key: 'puaRate',
    sorter: (a, b) => percentageToDecimal(a.puaRate) - percentageToDecimal(b.puaRate),
    tooltip: () => '劝退数÷入职数'
  },
  fuZeGaoXiaoShu: {
    title: '负责高校数',
    dataIndex: 'schoolCount',
    key: 'schoolCount',
    sorter: (a, b) => a.schoolCount - b.schoolCount,
    tooltip: () => '此HR-渠道负责人负责的高校累计数量'
  },
  yingJieBiYeBenKeShu: {
    title: '应届生毕业本科数',
    dataIndex: 'currentCount',
    key: 'currentCount',
    sorter: (a, b) => a.currentCount - b.currentCount,
    tooltip: () => '此HR-渠道负责人负责的高校应届生毕业本科数数量之和'
  },
  jianLiLiang: {
    title: '简历量',
    dataIndex: 'resumeCount',
    key: 'resumeCount',
    sorter: (a, b) => a.resumeCount - b.resumeCount,
    tooltip: () => '此HR-渠道负责人负责的高校简历投递数量之和'
  },
  jianLiWaJueLv: {
    title: '简历挖掘率',
    dataIndex: 'resumeRate',
    key: 'resumeRate',
    sorter: (a, b) => percentageToDecimal(a.resumeRate) - percentageToDecimal(b.resumeRate),
    tooltip: () => '简历量÷应届生毕业本科数'
  },
  ruZhiRenShu: {
    title: '入职人数',
    dataIndex: 'entryCount',
    key: 'entryCount',
    sorter: (a, b) => a.entryCount - b.entryCount,
    tooltip: () => '所有入职归属此渠道HR负责高校的数量'
  },
  muBiao: {
    title: '目标',
    dataIndex: 'targetCount',
    key: 'targetCount',
    sorter: (a, b) => a.targetCount - b.targetCount,
    tooltip: () => '手填'
  },
  muBiaoWanChengLv: {
    title: '目标完成率',
    dataIndex: 'targetRate',
    key: 'targetRate',
    sorter: (a, b) => percentageToDecimal(a.targetRate) - percentageToDecimal(b.targetRate),
    tooltip: () => '入职÷目标'
  },
  yueMianShu: {
    title: '约面数',
    dataIndex: 'arrangeFaceCount',
    key: 'arrangeFaceCount',
    sorter: (a, b) => a.arrangeFaceCount - b.arrangeFaceCount,
    tooltip: () => '此维护HR约面的数量'
  },
  daoMianShu: {
    title: '到面数',
    dataIndex: 'toFaceCount',
    key: 'toFaceCount',
    sorter: (a, b) => a.toFaceCount - b.toFaceCount,
    tooltip: () => '此维护HR所约的人，具体到面数量'
  },
  daoMianLv: {
    title: '到面率',
    dataIndex: 'toFaceRate',
    key: 'toFaceRate',
    sorter: (a, b) => percentageToDecimal(a.toFaceRate) - percentageToDecimal(b.toFaceRate),
    tooltip: () => '到面数÷约面数'
  },
  guoMianWeiHuShu: {
    title: '过面维护数',
    dataIndex: 'passFaceCount',
    key: 'passFaceCount',
    sorter: (a, b) => a.passFaceCount - b.passFaceCount,
    tooltip: () => '维护HR是此人，所有过面的状态的累计数量'
  },
  tuiPeiLv: {
    title: '退培率',
    dataIndex: 'exitTrainRate',
    key: 'exitTrainRate',
    sorter: (a, b) => percentageToDecimal(a.exitTrainRate) - percentageToDecimal(b.exitTrainRate),
    tooltip: () => '退培数÷到培人数'
  },
  peiXunQuanTuiShu: {
    title: '培训劝退数',
    dataIndex: 'puaTrainCount',
    key: 'puaTrainCount',
    sorter: (a, b) => a.puaTrainCount - b.puaTrainCount,
    tooltip: () => tabType === 'peiXunGuan' ? '此培训官参与的所有期培训中包含的【培训-培训中-中途劝退】状态的数量之和' : `【培训-培训中-中途劝退】状态归属此${tabType === 'weiHu' ? '维护HR' : '面试官'}的数量`
  },
  peiXunQuanTuiLv: {
    title: '劝退率',
    dataIndex: 'puaTrainRate',
    key: 'puaTrainRate',
    sorter: (a, b) => percentageToDecimal(a.puaTrainRate) - percentageToDecimal(b.puaTrainRate),
    tooltip: () => '培训劝退数÷到培数'
  },
  kaoHeTongGuoShu: {
    title: '考核通过数',
    key: 'examinePassCount',
    dataIndex: 'examinePassCount',
    sorter: (a, b) => a.examinePassCount - b.examinePassCount,
    tooltip: () => tabType === 'kaoHeGuan' ? '此考核官考核评价为【通过】的数量' : `考核评价中至少有1条为【通过】，归属此${tabType === 'weiHu' ? '维护HR' : tabType === 'peiXunGuan' ? '培训官' : '面试官'}的数量`
  },
  luQuShu: {
    title: '录取数',
    key: 'admissionCount',
    dataIndex: 'admissionCount',
    sorter: (a, b) => a.admissionCount - b.admissionCount,
    tooltip: () => `所有被录取归属此${tabType === 'weiHu' ? '维护HR' : tabType === 'peiXunGuan' ? '培训官' : '面试官'}的数量`
  },
  luQuLv: {
    title: '录取率',
    key: 'admissionRate',
    dataIndex: 'admissionRate',
    sorter: (a, b) => percentageToDecimal(a.admissionRate) - percentageToDecimal(b.admissionRate),
    tooltip: () => '录取数÷考核数'
  },
  mianShiShu: {
    title: '面试数',
    key: 'faceCount',
    dataIndex: 'faceCount',
    sorter: (a, b) => a.faceCount - b.faceCount,
    tooltip: () => '此面试官面试的数量'
  },
  guoMianShu: {
    title: '过面数',
    key: 'passFaceCount',
    dataIndex: 'passFaceCount',
    sorter: (a, b) => a.passFaceCount - b.passFaceCount,
    tooltip: () => '此面试官面试通过的数量'
  },
  guoMianLv: {
    title: '过面率',
    key: 'passFaceRate',
    dataIndex: 'passFaceRate',
    sorter: (a, b) => percentageToDecimal(a.passFaceRate) - percentageToDecimal(b.passFaceRate),
    tooltip: () => '过面数÷面试数'
  },
  daoPeiShu: {
    title: '到培数',
    key: 'toTrainCount',
    dataIndex: 'toTrainCount',
    sorter: (a, b) => a.toTrainCount - b.toTrainCount,
    tooltip: () => `经历过【到培】状态归属此${tabType === 'weiHu' ? '维护HR' : '面试官'}的数量`
  },
  tuiPeiShu: {
    title: '退培数',
    key: 'exitTrainCount',
    dataIndex: 'exitTrainCount',
    sorter: (a, b) => a.exitTrainCount - b.exitTrainCount,
    tooltip: () => tabType === 'peiXunGuan' ? '此培训官参与的所有期培训中包含的【培训-培训中-中途放弃】状态的数量之和' : `【培训-培训中-中途放弃】状态归属此${tabType === 'weiHu' ? '维护HR' : '面试官'}的数量`
  },
  peiXunQiShu: {
    title: '培训期数',
    key: 'trainCount',
    dataIndex: 'trainCount',
    sorter: (a, b) => a.trainCount - b.trainCount,
    tooltip: () => '此培训官共参与过几期培训'
  },
  peiXunRenShu: {
    title: '培训人数',
    key: 'trainUserCount',
    dataIndex: 'trainUserCount',
    sorter: (a, b) => a.trainUserCount - b.trainUserCount,
    tooltip: () => '此培训官参与的所有期培训包含的到培人数之和'
  },
}

export const otherColumns: any = {
  quDao: [
    {
      ...commonColumns.channel,
      title: '渠道HR'
    },
    commonColumns.phone,
    commonColumns.fuZeGaoXiaoShu,
    commonColumns.yingJieBiYeBenKeShu,
    commonColumns.jianLiLiang,
    commonColumns.jianLiWaJueLv,
    commonColumns.ruZhiRenShu,
    commonColumns.ruZhiLv,
    commonColumns.muBiao,
    commonColumns.muBiaoWanChengLv,
  ],
  weiHu: [
    {
      ...commonColumns.preserveUserId,
      title: '维护HR'
    },
    commonColumns.phone,
    commonColumns.yueMianShu,
    commonColumns.daoMianShu,
    commonColumns.daoMianLv,
    commonColumns.guoMianWeiHuShu,
    commonColumns.daoPeiShu,
    commonColumns.tuiPeiShu,
    commonColumns.tuiPeiLv,
    commonColumns.peiXunQuanTuiShu,
    commonColumns.peiXunQuanTuiLv,
    commonColumns.kaoHeShu,
    commonColumns.kaoHeTongGuoShu,
    commonColumns.tongGuoLv,
    commonColumns.luQuShu,
    commonColumns.luQuLv,
    commonColumns.ruZhiShu,
    commonColumns.ruZhiLv,
    commonColumns.liZhiShu,
    commonColumns.liZhiLv,
    commonColumns.quanTuiShu,
    commonColumns.quanTuiLv
  ],
  mianShiGuan: [
    {
      ...commonColumns.interviewOfficer,
      title: '面试官'
    },
    commonColumns.phone,
    commonColumns.mianShiShu,
    commonColumns.guoMianShu,
    commonColumns.guoMianLv,
    commonColumns.daoPeiShu,
    commonColumns.tuiPeiShu,
    commonColumns.tuiPeiLv,
    commonColumns.peiXunQuanTuiShu,
    commonColumns.peiXunQuanTuiLv,
    commonColumns.kaoHeShu,
    commonColumns.kaoHeTongGuoShu,
    commonColumns.tongGuoLv,
    commonColumns.luQuShu,
    commonColumns.luQuLv,
    commonColumns.ruZhiShu,
    commonColumns.ruZhiLv,
    commonColumns.liZhiShu,
    commonColumns.liZhiLv,
    commonColumns.quanTuiShu,
    commonColumns.quanTuiLv,
  ],
  peiXunGuan: [
    {
      ...commonColumns.trainers,
      title: '培训官'
    },
    commonColumns.phone,
    commonColumns.peiXunQiShu,
    commonColumns.peiXunRenShu,
    commonColumns.tuiPeiShu,
    commonColumns.tuiPeiLv,
    commonColumns.peiXunQuanTuiShu,
    commonColumns.quanTuiLv,
    commonColumns.kaoHeShu,
    commonColumns.kaoHeTongGuoShu,
    commonColumns.tongGuoLv,
    commonColumns.luQuShu,
    commonColumns.ruZhiShu,
    commonColumns.ruZhiLv,
    commonColumns.liZhiShu,
    commonColumns.liZhiLv,
    commonColumns.quanTuiShu,
    commonColumns.quanTuiLv,
  ],
  kaoHeGuan: [
    {
      ...commonColumns.examers,
      title: '考核官'
    },
    commonColumns.phone,
    commonColumns.kaoHeShu,
    commonColumns.kaoHeTongGuoShu,
    commonColumns.tongGuoLv,
    commonColumns.ruZhiShu,
    commonColumns.ruZhiLv,
    commonColumns.liZhiShu,
    commonColumns.liZhiLv,
    commonColumns.quanTuiShu,
    commonColumns.quanTuiLv,
  ]
}


export const selectOptions: any = {
  name: {
    placeholder: '姓名',
    inputValue: ''
  },
  phone: {
    placeholder: '手机号',
    inputValue: ''
  },
  channel: {
    requestType: 'CHANNEL',
    requestApi: 'selectUserByRole',
    placeholder: '渠道HR',
    option: []
  },
  interviewUserId: {
    requestType: 'HR',
    requestApi: 'selectUserByRole',
    placeholder: '约面HR',
    option: []
  },
  preserveUserId: {
    requestType: 'HR',
    requestApi: 'selectUserByRole',
    placeholder: '维护HR',
    option: []
  },
  interviewOfficer: {
    requestType: 'INTERVIEW',
    requestApi: 'selectUserByRole',
    placeholder: '面试官',
    option: []
  },
  examers: {
    requestType: 'ASSESS',
    requestApi: 'selectUserByRole',
    placeholder: '考核官',
    option: []
  },
  trainers: {
    requestType: 'TRAINING',
    requestApi: 'selectUserByRole',
    placeholder: '培训官',
    option: []
  },
}

function percentageToDecimal(percentage) {
  let decimal = parseFloat(percentage.slice(0, -1)) / 100;
  return decimal;
}




